package com.easyCode.sqlBuilder.oop;

import com.easyCode.sqlBuilder.ConfigureSqlBuilder;
import com.easyCode.sqlBuilder.SqlBuilder;
import com.easyCode.sqlBuilder.SqlInfo;
import com.easyCode.sqlBuilder.sqlInfo.BaseDataBaseSqlInfo;
import com.easyCode.sqlManager.GlobalProperties;
import com.easyCode.sqlManager.MappingContainer;
import com.easyCode.sqlMapper.mapInfo.DataBaseMapInfo;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * @author 大忽悠
 * @create 2022/12/8 20:46
 */
@Data
@Slf4j
public class OopSqlBuilder implements ConfigureSqlBuilder {
    /**
     * 数据库类型
     */
    private BaseDataBaseSqlInfo dataBaseSqlInfo;
    /**
     * 添加数据库创建的sql语句: CREATE DATABASE [IF NOT EXISTS] dbname;
     */
    private Boolean createDataBase=Boolean.TRUE;
    /**
     * 负责完成解析工作
     */
    private OopMapper oopMapper;

    /**
     * 防止构建两次
     */
    private Boolean build=Boolean.FALSE;

    public OopSqlBuilder(BaseDataBaseSqlInfo baseDataBaseSqlInfo) {
        this.dataBaseSqlInfo= baseDataBaseSqlInfo;
        oopMapper=new OopMapper();
    }

    /**
     * @return 返回构建得到的sql语句给SqlExec执行
     */
    @Override
    public String build() {
        if(build){
            throw new RuntimeException("OopSqlBuilder已经构建过了,多次构建会产生副作用!");
        }
        build=true;
        oopMapper.mapper(dataBaseSqlInfo);
        return dataBaseSqlInfo.buildSql();
    }

    /**
     * @return 返回构建得到的sqlInfo
     */
    @Override
    public BaseDataBaseSqlInfo getSqlInfo() {
        return dataBaseSqlInfo;
    }

    @Override
    public void setSqlInfo(BaseDataBaseSqlInfo sqlInfo) {
        this.dataBaseSqlInfo=sqlInfo;
    }


    public void addMapperObject(Object ... mapperObjList){
          oopMapper.addMapperObj(mapperObjList);
    }
}
